﻿using Microsoft.EntityFrameworkCore;
using MyERP.Models;
using System;

namespace MyERP
{
    /// <summary>
    /// 数据库上下文
    /// </summary>
    public class MyDbContext:DbContext
    {
        // 构造函数，接受 DbContextOptions<AppDbContext> 参数
        public MyDbContext(DbContextOptions<MyDbContext> options) : base(options)
        {
        }

        /// <summary>
        /// 声明表对象
        /// </summary>
        public DbSet<Client> Client { get; set; }
        public DbSet<Goods> Goods { get; set; }
        public DbSet<PurchaseOrder> PurchaseOrder { get; set; }
        public DbSet<Supplier> Supplier { get; set; }
        public DbSet<Payment> Payments { get; set; }
        public DbSet<SalesTicket> SalesTicket { get; set; }
        public DbSet<Proceeds> Proceeds { get; set; }
        public DbSet<Users> Users { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            //加载当前程序集中所有实现了IEntityTypeConfiguration接口的类
            modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
        }
    }
}
